# 基础步骤类
from abc import ABC, abstractmethod
from typing import Union

from action import ActionType


class BaseStep(ABC):
    @property
    @abstractmethod
    def action(self) -> ActionType:
        """步骤操作类型（子类必须实现）"""
        ...

    def __init__(self, **kwargs):
        self.description = kwargs["description"]  # 步骤描述


class ClickStep(BaseStep):
    action: ActionType = ActionType.CLICK

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.selector = kwargs["selector"]


class GotoStep(BaseStep):
    action: ActionType = ActionType.GOTO

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.url = kwargs["url"]


class InputStep(BaseStep):
    action: ActionType = ActionType.INPUT

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.selector = kwargs["selector"]
        self.value = kwargs["value"]


class SleepStep(BaseStep):
    action: ActionType = ActionType.SLEEP

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.timeout = kwargs["timeout"]


class ScreenshotStep(BaseStep):
    action: ActionType = ActionType.SCREENSHOT

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.fileName = kwargs["fileName"]


# 增加等待操作步骤
class WaitForSelectorStep(BaseStep):
    action: ActionType = ActionType.WAIT_FOR_SELECTOR

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.selector = kwargs["selector"]
        self.timeout = kwargs["timeout"]

class ExecStep(BaseStep):
    action: ActionType = ActionType.EXEC

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.expression = kwargs["expression"]

class JsEvaluateStep(BaseStep):
    action: ActionType = ActionType.JSEVALUATE

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.expression = kwargs["expression"]
